<?xml version="1.0" encoding="UTF-8" ?>

<sqlMap namespace="LineItem" 
xmlns="http://ibatis.apache.org/mapping" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >

	<alias>
		<typeAlias alias="LineItem" type="MyBatis.DataMapper.SqlClient.Test.Domain.LineItem, MyBatis.DataMapper.SqlClient.Test" />
		<typeAlias alias="LineItemCollection" type="MyBatis.DataMapper.SqlClient.Test.Domain.LineItemCollection, MyBatis.DataMapper.SqlClient.Test" />
    <typeAlias alias="LineItemCollection2" type="${collection2Namespace}" />
    <typeAlias alias="GenericListLineItem" type="MyBatis.DataMapper.SqlClient.Test.Domain.ListeEntiteMetier`1[[MyBatis.DataMapper.SqlClient.Test.Domain.LineItem, MyBatis.DataMapper.SqlClient.Test]], MyBatis.DataMapper.SqlClient.Test" />
  </alias>
	
	<resultMaps>  	
		<resultMap id="LineItem-Price" class="decimal">
			<result property="value"		column="LineItem_Price"/>
		</resultMap>
		
		<resultMap id="LineItem" class="LineItem">
			<result property="Id"			column="LineItem_ID"/>
			<result property="Code"			column="LineItem_Code"/>
			<result property="Quantity"		column="LineItem_Quantity"/>
			<result property="Price"		column="LineItem_Price" />
    </resultMap>

    <resultMap id="LineItemWithNullReplacement" class="LineItem">
      <result property="Id"			column="LineItem_ID"/>
      <result property="Code"			column="LineItem_Code"/>
      <result property="Quantity"		column="LineItem_Quantity"/>
      <result property="Price"		column="LineItem_Price" nullValue="-77.77" />
		</resultMap>
		
	</resultMaps>  
	
	<statements>

    <statement id="GetLineItemsForOrderWithGenericList"
      parameterClass="int"
      listClass="GenericListLineItem"
      resultClass="LineItem">
      select
      LineItem_ID as Id,
      LineItem_Code as Code,
      LineItem_Quantity as Quantity,
      LineItem_Price as Price
      from LineItems where Order_ID = #value#
      order by LineItem_Code
    </statement>
    
    <statement id="GetLineItemsForOrder" parameterClass="int" resultClass="LineItem" listClass="GenericListLineItem">
      select 
        LineItem_ID as Id, 
        LineItem_Code as Code, 
        LineItem_Quantity as Quantity, 
        LineItem_Price as Price 
        from LineItems where 
      Order_ID = #value#
    </statement>
    
    
    <statement id="GetSpecificLineItem-JIRA-251"
				parameterClass="Hashtable"
				resultClass="LineItem">
      select
      LineItem_ID as Id,
      LineItem_Code as Code,
      LineItem_Quantity as Quantity,
      LineItem_Price as Price
      from LineItems
      where Order_ID = #Order_ID#
      and LineItem_ID = #Order_FavouriteLineItem#
    </statement>
    
    <procedure id="SelectLineItemForOrder" parameterMap="select-params" resultClass="LineItem">
      ps_SelectLineItem
    </procedure>
    
		<statement id="GetLineItemPrice"
					parameterClass="Hashtable"
					resultMap="LineItem-Price" >
			select
				LineItem_Price
				from LineItems
				where Order_ID = #Order_ID#
				and LineItem_ID = #LineItem_ID#
		</statement>
		
		<statement id="GetLineItemsForOrder"
			parameterClass="int"
			resultClass="LineItem">
			select
				LineItem_ID as Id,
				LineItem_Code as Code,
				LineItem_Quantity as Quantity,
				LineItem_Price as Price
			from LineItems where Order_ID = #value#
		</statement>
		
		<statement id="GetLineItemsForOrderWithListClass"
			parameterClass="int"
			listClass="LineItemCollection"
			resultClass="LineItem">
			select
				LineItem_ID as Id,
				LineItem_Code as Code,
				LineItem_Quantity as Quantity,
				LineItem_Price as Price
			from LineItems where Order_ID = #value#
			order by LineItem_Code
		</statement>

    <statement id="GetLineItemsForOrderWithListClass2"
      parameterClass="int"
      listClass="LineItemCollection2"
      resultClass="LineItem">
        select
        LineItem_ID as Id,
        LineItem_Code as Code,
        LineItem_Quantity as Quantity,
        LineItem_Price as Price
        from LineItems where Order_ID = #value#
        order by LineItem_Code
    </statement>
    
		<statement id="GetSpecificLineItem"
					parameterClass="Hashtable"
					resultClass="LineItem">
			select
				LineItem_ID as Id,
				LineItem_Code as Code,
				LineItem_Quantity as Quantity,
				LineItem_Price as Price
				from LineItems
			where Order_ID = #Order_ID#
				and LineItem_ID = #LineItem_ID#
		</statement>
		
		<statement id="GetSpecificLineItemWithPicture"
					parameterClass="Hashtable"
					resultClass="LineItem">
			select
				LineItem_ID as Id,
				LineItem_Code as Code,
				LineItem_Quantity as Quantity,
				LineItem_Price as Price,
				LineItem_Picture as PictureData				
				from LineItems
			where Order_ID = #Order_ID#
				and LineItem_ID = #LineItem_ID#
		</statement>
		
		<select id="GetDynSpecificLineItem"
			parameterClass="HashMap"
			resultClass="LineItem">
			select
				LineItem_ID as Id,
				LineItem_Code as Code,
				LineItem_Quantity as Quantity,
				LineItem_Price as Price
				from LineItems
			where Order_ID = #Order_ID:Int#
			<dynamic>
				<isNotNull property="LineItem_ID">
					and LineItem_ID = #LineItem_ID:Int#
				</isNotNull>
			</dynamic>
		</select>
		
		<statement id="GetSpecificLineItemWithNullReplacement"
					parameterClass="int"
					resultMap="LineItemWithNullReplacement">
			select
				LineItem_ID,
				LineItem_Code,
				LineItem_Quantity,
				LineItem_Price
				from LineItems
				where LineItem_ID =  #value#
		</statement>
		
		<statement id="InsertLineItem" 
					parameterMap="insert-params" >
			insert into LineItems
			(LineItem_ID, Order_ID, LineItem_Code, LineItem_Quantity, LineItem_Price)
			values
			(?, ?, ?, ?, ?);
		</statement>
		
		<statement id="InsertLineItemWithPicture" 
					parameterMap="insert-params-picture" >
			insert into LineItems
			(LineItem_ID, Order_ID, LineItem_Code, LineItem_Quantity, LineItem_Price, LineItem_Picture)
			values
			(?, ?, ?, ?, ?, ?);
		</statement>
		
		<insert id="InsertLineItemPostKey" parameterClass="LineItem">
			insert into LineItems
			(LineItem_ID, Order_ID, LineItem_Code, LineItem_Quantity, LineItem_Price)
			values
			(#Id#, #Order.Id#, #Code#, #Quantity#, #Price:Decimal#)
			<selectKey property="Id" type="post" resultClass="int" >
				select 99 from LineItems where LineItem_ID = 1 and Order_ID=1
			</selectKey>
		</insert>	
		
		 <insert id="InsertLineItemPreKey" parameterClass="LineItem">
			<selectKey property="Id" type="pre" resultClass="int" >
				select 99 from LineItems where LineItem_ID = 1 and Order_ID=1
			</selectKey>
			insert into LineItems
			(LineItem_ID, Order_ID, LineItem_Code, LineItem_Quantity, LineItem_Price)
			values
			(#Id#, #Order.Id#, #Code#, #Quantity#, #Price:Decimal#)
		</insert>
  
		<insert id="InsertLineItemNoKey" parameterClass="LineItem">
			insert into LineItems
			(LineItem_ID, Order_ID, LineItem_Code, LineItem_Quantity, LineItem_Price)
			values
			(#Id#, #Order.Id#, #Code#, #Quantity#, #Price:Decimal#)
		</insert>
  
  		<!-- JIRA 23 -->
		<delete id="DeleteWithComments" >
			<!-- Delete LineItems -->
			delete from LineItems where Order_ID = 10
			<!-- Delete LineItems -->
			delete from LineItems where Order_ID = 9
		</delete>
		
  </statements>
	

  
	<parameterMaps>

    <parameterMap id="select-params" class="int">
      <parameter property="Order_ID" />
    </parameterMap>
    
		<parameterMap id="insert-params" class="LineItem">
			<parameter property="Id" />
			<parameter property="Order.Id" />
			<parameter property="Code" />			
			<parameter property="Quantity" />
			<parameter property="Price" dbType="Decimal" nullValue="-99.99"/>
		</parameterMap>
				
		<parameterMap id="insert-params-picture" class="LineItem">
			<parameter property="Id" />
			<parameter property="Order.Id" />
			<parameter property="Code" />			
			<parameter property="Quantity" />
			<parameter property="Price" dbType="Decimal" />
			<parameter property="PictureData" dbType="Image" />
		</parameterMap>
		
	</parameterMaps>
</sqlMap>